package com.supermap.test;


import com.supermap.data.*;
import com.supermap.data.conversion.*;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class DWGExporter {
    private static Datasource datasource = null;

    public DWGExporter(Datasource datasource) {
        this.datasource = datasource;
    }

    public static void main(String[] args) throws Exception {



        PrjCoordSys prjCoordSys = PrjCoordSys.fromEPSG(4490);
        System.out.println(prjCoordSys.getEPSGCode());

//        Workspace workspace = new Workspace();
//        WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(
//                "E:\\MapData\\202411\\dwgExport\\WorkSpace.smwu");
//        conInfo.setType(WorkspaceType.SMWU);
//        workspace.open(conInfo);
//        datasource= workspace.getDatasources().get(0);
//        Dataset dataset = datasource.getDatasets().get("result_simpleToCAD");
//        exportDWG(dataset, "E:\\MapData\\202411\\dwgExport\\simpleToCAD.dwg");

    }
    

    private static void exportDWG(Dataset dataset, String dwgPath) throws Exception {
        if (!new File(dwgPath).exists()) {
            new File(dwgPath).createNewFile();
        }

        ExportSettingDWG exportSettingDWG = new ExportSettingDWG();
        exportSettingDWG.setOverwrite(true);
        exportSettingDWG.setTargetFilePath(dwgPath);
        exportSettingDWG.setTargetFileCharset(Charset.UTF8);

        exportSettingDWG.setStyleMappingTableFile("E:\\MapData\\202411\\dwgExport\\PlanLibrary对照.stt");
        exportSettingDWG.setSourceData(dataset);
        //exportSettingVCT.setSourceDatas(datasetVectorList.toArray());
        DataExport dataExport = new DataExport();
        dataExport.getExportSettings().add(exportSettingDWG);
        dataExport.addExportSteppedListener(exportSteppedEvent ->
        {
            System.out.println(exportSteppedEvent.getTotalPercent());
            System.out.println(exportSteppedEvent.getCount());
        });
        ExportResult exportResult = dataExport.run();

        if (exportResult.getFailedSettings() != null && exportResult.getFailedSettings().length > 0) {
            System.err.println("exportResult.getFailedSettings()[0]");
            System.out.println(exportResult.getFailedSettings()[0]);
        }
        dataExport.dispose();
    }
}
